package com.xuetang9.fujian.net.request;

import com.xuetang9.fujian.dao.UserDao;
import com.xuetang9.fujian.model.User;
import com.xuetang9.fujian.net.server.ECQServer;
import com.xuetang9.fujian.net.server.SocketHandler;

import java.util.HashMap;
import java.util.Objects;

/**
 * @describe:
 * @author:fujian
 * @date:2021/6/13
 * @Version: V1.0
 * @Package: com.xuetang9.fujian.net.request
 */
@SuppressWarnings("all")
public class LoginRequestHandler extends AbstractRequestHandler{
    private UserDao dao = new UserDao();
    @Override
    public void handleRequest(HashMap<String, Object> message, SocketHandler handler, ECQServer server) {
        User loginUser = (User) message.get("loginUser");
//        System.out.println(loginUser);
        User user = dao.get(loginUser.getAccount());
//        System.out.println(user);
        HashMap<String, Object> reponseMessage = new HashMap<>();
        if (Objects.isNull(user)){
            reponseMessage.put("success",false);
        }else {
            if (!user.getPassword().equals(loginUser.getPassword())){
                reponseMessage.put("success",false);
            }else {
                reponseMessage.put("success",true);
                reponseMessage.put("loginUser",user);
            }
        }
        reponseMessage.put("handlerClass","com.xuetang9.fujian.net.reponse.LoginResponseHandler");
        handler.sendMessage(reponseMessage);
    }
}
